<?php
namespace app\gym\controller;
use app\common\controller\AdminBase;
/*小型健身房会员管理系统--- 上课历史记录*/
class GymCourseHistory extends AdminBase{
	protected $beforeActionList = [
        'before_index'=>['only'=>'index'],
    ];
	function _initialize() {
		parent::_initialize();
    }
	function index(){
		echo $this->fetch();
	}	
	function ajax_index(){
		$this->ajax($this->_ajax_index());
	}
	
	///////////////////////////////////////////////////////////////////////////////////
	/**
	 * 权限菜单
	 **/
	function before_index(){
		$auth_group=sp_get_auth_menu_3("10071002");
		$this->assign("menus",$auth_group);
	}
	/*获取卡数据*/
	private function _ajax_index(){
		$query=array();
		$shop_id=sp_get_current_shop_id();
		$draw=input("draw",0)+1;//请求时间		 
		$where_and=join(" and ",sp_get_param_sql(request()->isPost(),$query));
		$where_and.=" and a.shop_id=$shop_id  ";
		$field="a.course_name,a.course_count,a.up_time,a.down_time,b.name as member_name,c.name as pt_name";
		$total=db("GymCourseHistory")->alias("a")->join([['m_gym_member b',"a.member_id=b.id ","LEFT"],['m_gym_employee c',"c.id=a.pt_id","LEFT"]])->where($where_and)->fetchsql(FALSE)->count(1);
		$list=db("GymCourseHistory")->alias("a")->field($field)->join([['m_gym_member b',"a.member_id=b.id ","LEFT"],['m_gym_employee c',"c.id=a.pt_id","LEFT"]])->where($where_and)->order("a.id desc")->limit($this->get_limit())->fetchsql(FALSE)->select();
		return array('pageData'=>$list,'total'=>$total,"draw"=>$draw);
	}

}
